package com.lzx.iteam;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.lzx.iteam.R;
import com.lzx.iteam.util.StringUtil;

/**
 * Created by hfx_lk on 15-1-29.
 */
public class UpdateGroupNameActivity extends Activity implements View.OnClickListener {
    private Context mContext;
    private TextView mTvConfirm;
    private LinearLayout mLlBack;
    private EditText mEtName;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update_groupname_layout);
        mContext = UpdateGroupNameActivity.this;
        initView();
    }

    private void initView() {
        mLlBack = (LinearLayout) findViewById(R.id.update_groupname_btn_back);
        mLlBack.setOnClickListener(this);
        mTvConfirm = (TextView) findViewById(R.id.tv_confrim);
        mTvConfirm.setOnClickListener(this);
        mEtName = (EditText) findViewById(R.id.et_new_group_name);
        mEtName.setText(getIntent().getStringExtra("old_name"));
        mEtName.setSelection(mEtName.getText().length());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.update_groupname_btn_back:
                UpdateGroupNameActivity.this.finish();
                break;
            case R.id.tv_confrim:
                String newName = mEtName.getText().toString();
                if(StringUtil.isEmpty(newName)){
                    Toast.makeText(mContext,"号码簿名称不能为空",Toast.LENGTH_SHORT).show();
                }else{
                    Intent intent = new Intent();
                    intent.putExtra("new_name",newName);
                    setResult(RESULT_OK,intent);
                    finish();
                }
                break;
        }
    }
}